--[[ 编码: JX-52-17 名称: 出库分拣-条码输入变化后 作者:HAN 日期:2025-1-29 级别:固定 (说明本段代码在项目中不太会变化) 函数: AfterUPCChange 功能: -- 根据输入的条码到【Material_Barcode】找到货品编码 -- 如果当前入库任务的货品编码相同 组盘数量+1 更改记录: V2.0 HAN 20250422 JX_Material_Barcode 改为 Material_Barcode --]] jx_base= require( "jx_base" ) function AfterUPCChange ( strLuaDEID ) local nRet, strRetInfo -- 获取UPC nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "UPC","S_ITEM_CODE","F_ACC_P_QTY", "F_QTY", "TaskFinish") if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local obj_attrs = json.decode( strRetInfo ) local upc = lua.Get_StrAttrValue( obj_attrs[1].value ) local item_code = lua.Get_StrAttrValue( obj_attrs[2].value ) local acc_p_qty = lua.Get_NumAttrValue( obj_attrs[3].value ) local qty = lua.Get_NumAttrValue( obj_attrs[4].value ) local task_finish = lua.Get_NumAttrValue( obj_attrs[5].value ) -- 1 表示任务强制完成 local str_prompt = "请扫商品编码..." local qty_input_enable = false -- 分拣数量输入框是否可以输入 if ( upc == '' ) then return end local runtime_parameter nRet, runtime_parameter = m3.GetRuntimeParam(strLuaDEID) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! "..runtime_parameter ) end -- 获取【组盘输入】面板的参数 local parameter nRet, parameter = m3.GetRuntimePanel_InputParamter( strLuaDEID, runtime_parameter.panel, "出库分拣" ) if ( nRet == 1 ) then mobox.setInfo( strLuaDEID, "没有定义'出库分拣'面板参数!") return end if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), parameter ) end if ( parameter == nil ) then return end -- V3.0 if ( acc_p_qty == qty or task_finish == 1 ) then -- 扫码进入的应该是拣货箱编码 if ( upc ~= parameter.pick_box_code ) then -- 扫码的拣货箱编码不正确 str_prompt = "请扫拣货箱编码..." mobox.setInfo( strLuaDEID, "扫码绑定的拣货箱编码不正确!") goto set_dlg_attr else -- 分拣任务完成 local id = parameter.id -- 当前点中的入库任务标识 local dc_no = parameter.dc_no -- 当前点中的入库任务所属配盘号 if ( dc_no == nil or dc_no == "") then mobox.setInfo( strLuaDEID, "'出库分拣'面板必须有配盘号参数!") return end -- 设置【配盘明细】状态 = 2(组盘完成) local strCondition = "S_ID = '"..id.."'" local strUpdateSql = "N_B_STATE = 2, F_ACC_P_QTY = "..acc_p_qty nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Distribution_CNTR_Detail", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【配盘明细】信息失败!"..strRetInfo ) end -- 拣出的货品和拣料箱进行绑定(+CG_Detail) if ( parameter.pick_box_code ~= '' and parameter.pick_box_code ~= nil and acc_p_qty > 0 ) then local cg_detail = m3.AllocObject(strLuaDEID,"CG_Detail") cg_detail.cntr_code = parameter.pick_box_code cg_detail.item_code = parameter.item_code cg_detail.item_name = parameter.item_name cg_detail.qty = acc_p_qty cg_detail.uom = "个" nRet, cg_detail = m3.CreateDataObj( strLuaDEID, cg_detail ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '创建拣料箱CG_Detail时失败!'..cg_detail ) end end local action nRet, action = jx_base.Distribution_CNTR_PostProcess( strLuaDEID, parameter ) if ( nRet ~= 0 ) then mobox.stopProgram( strLuaDEID, action ) return end nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end return end else -- 通过条码找到物料编码 local material_barcode nRet, material_barcode = m3.GetDataObjectByKey(strLuaDEID, "Material_Barcode", "S_BARCODE", upc) if (nRet ~= 0 ) then if ( nRet == 1 ) then mobox.setInfo( strLuaDEID, "条码'"..upc.."'没有对应的货品,请检查物料条码对照表!") goto set_dlg_attr end lua.Error( strLuaDEID, debug.getinfo(1), "获取【物料条码】信息失败! " .. material_barcode ) end -- 判断扫码的货品是否是目前的入库任务 if ( item_code ~= material_barcode.item_code ) then mobox.setInfo( strLuaDEID, "条码'"..upc.."'对应的货品编码='"..material_barcode.item_code.."不是当前入库任务中的货物!") goto set_dlg_attr end acc_p_qty = acc_p_qty + 1 qty_input_enable = true if ( qty == acc_p_qty ) then str_prompt = "请扫拣货箱编码..." end end ::set_dlg_attr:: local action = { { action_type = "set_panel_dlg_attr", value = { panel_name = "出库分拣", attrs = { { attr = "F_ACC_P_QTY", value = acc_p_qty, enable = qty_input_enable }, { attr = "UPC", value = "", prompt = str_prompt }, { attr = "Prompt", value = str_prompt } } } } } lua.Debug( strLuaDEID, debug.getinfo(1), "action", action ) nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo ) end end